package com.example.demo.service;

import com.example.demo.entity.SysUser;
import com.example.demo.repo.SysUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class CustomUserService implements UserDetailsService {
    @Autowired
    private SysUserRepository sysUserRepository;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SysUser sysUser=sysUserRepository.findByUsername(s);
        System.out.println(sysUser.getPassword()+"    "+sysUser.getUsername());
        if(null==sysUser){
            throw  new UsernameNotFoundException("用户不存在");
        }

        return sysUser;
    }
}
